﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp_Calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            comboBox1.Items.Add("+");
            comboBox1.Items.Add("-");
            comboBox1.Items.Add("*");
            comboBox1.Items.Add("/");
            comboBox1.Items.Add("%");
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Visible = false; // Don't put it after all the if statements. 
            if (comboBox1.Text == "+") {
                this.richTextBox1.Visible = true;
                richTextBox1.Text = (double.Parse(textBox1.Text) + double.Parse(textBox3.Text)).ToString();
            }
            if (comboBox1.Text == "-")
            {
                this.richTextBox1.Visible = true;
                richTextBox1.Text = (double.Parse(textBox1.Text) - double.Parse(textBox3.Text)).ToString();
            }
            if (comboBox1.Text == "*")
            {
                this.richTextBox1.Visible = true;
                richTextBox1.Text = (double.Parse(textBox1.Text) * double.Parse(textBox3.Text)).ToString();
            }
            if (comboBox1.Text == "/")
            {
                if (double.Parse(textBox3.Text) == 0)
                {
                    this.richTextBox1.Visible = false;
                    richTextBox1.Text = "错误运算数";
                }
                else
                {
                    this.richTextBox1.Visible = true;
                    richTextBox1.Text = (double.Parse(textBox1.Text) / double.Parse(textBox3.Text)).ToString();
                }
            }
            if (comboBox1.Text == "%")
            {
                if (double.Parse(textBox3.Text) == 0)
                {
                    this.richTextBox1.Visible = true;
                    richTextBox1.Text = "错误运算数";
                }
                else
                {
                    this.richTextBox1.Visible = true;
                    richTextBox1.Text = (double.Parse(textBox1.Text) % double.Parse(textBox3.Text)).ToString();
                }
            }
        }

        private void label4_Click_1(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            comboBox1.SelectedIndex = -1;
            textBox3.Clear();
            richTextBox1.Clear();
            richTextBox1.Visible = false;
        }
    }
}
